package com.study.hot.jetpack.demo_shopping.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.navOptions
import com.study.hot.R
import kotlinx.android.synthetic.main.welcome_fragment.*
import org.jetbrains.anko.sdk27.coroutines.onClick

/**
 * <pre>
 *     author : fauks
 *     time   : 2020/03/25
 *     desc   :
 * </pre>
 */
class WelcomeFragment : Fragment() {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.welcome_fragment, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        //利用ID导航
        btn_login.onClick {
            //设置动画参数
            val navOpt = navOptions {
                anim {
                    enter = R.anim.common_slide_in_right
                    exit = R.anim.common_slide_out_left
                    popEnter = R.anim.common_slide_in_left
                    popExit = R.anim.common_slide_out_right
                }
            }
            //设置参数
            val bundle = Bundle()
            bundle.putString("name", "fauks")
            findNavController().navigate(R.id.login, bundle, navOpt)
        }

        //利用safe args
        /*btn_register.onClick {
            val action = WelcomeFragmentDirections
                    .actionWelcomeFragmentToRegisterFragment()
                    .setEmail("xiaofauks@163.com")
            findNavController().navigate(action)
        }*/
    }
}